package com.qishao.service_base.error;

import com.qishao.service_base.reponse.Response;
import com.qishao.service_base.utils.ExceptionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常返回格式处理类
 * @Author： xushaoqi
 * @Date：2021/8/14
 */
@ControllerAdvice
@Slf4j
public class UnifiedExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Response error(Exception e){
        log.error(ExceptionUtil.getMessage(e));
        e.printStackTrace();
        return Response.error();
    }

}
